package com.blog.dao.impl;

import com.blog.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;


/**
 * Created with IntelliJ IDEA.
 * Author:  Wu Yujie
 * Email:  coffee377@dingtalk.com
 * Time:  2017/02/23 19:36
 */
@Repository
public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {

    /**
     * 构造器注入数据源
     * @param dataSource    数据源
     */
    @Autowired
    public AccountDaoImpl(DataSource dataSource) {
        super.setDataSource(dataSource);
    }


    @Override
    public void outMoney(String out, Double money) {
        String sql = "UPDATE account SET money = money - ? WHERE name = ?";
        getJdbcTemplate().update(sql, money, out);
    }

    @Override
    public void inMoney(String in, Double money) {
        String sql = "UPDATE account SET money = money + ? WHERE name = ?";
        getJdbcTemplate().update(sql, money, in);
    }
}
